package com.kgc.onlineLife.service.impl;

import com.kgc.onlineLife.bean.Product;
import com.kgc.onlineLife.mapper.ProductMapper;
import com.kgc.onlineLife.service.ProductService;
import com.kgc.onlineLife.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created On : 2022/4/16.
 * <p>
 * Author     : nainai
 * <p>
 * Description: ProductServiceImpl
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;


    @Override
    public List<Product> queryProducts(Page page) {
        return productMapper.selectProducts(page);
    }

    @Override
    public List<Product> queryOnlineProductByCid(Integer cid) {
        return productMapper.selectOnlineProductByCid(cid);
    }

    @Override
    public List<Product> queryProductsByName(String name) {
        return productMapper.selectProductsByName(name);
    }

    @Override
    public Product queryProductById(Integer id) {
        return productMapper.selectProductByIdM(id);
    }

    @Override
    public boolean removeProductById(Integer id) {
        return productMapper.deleteProductById(id) > 0;
    }

    @Override
    public boolean modOnline(Integer id) {
        return productMapper.updateProductOnlineById(id, productMapper.selectProductByIdM(id).getStatus() == 1 ? 0 : 1) > 0;
    }

    @Override
    public boolean addProduct(Product product) {
        return productMapper.insertProduct(product) > 0;
    }

    @Override
    public boolean modProductById(Product product) {
        return productMapper.updateProductById(product) > 0;
    }

}
